home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: upgradeLock.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:55:51 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "pool.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "semaphore.h"
- #include "link.h"
- #include "lsn.h"
- #include "latch.h"
- #include "bf.h"
- #include "volume.h"
- #include "trans.h"
- #include "threadstate.h"
- #include "lm_intfuncs.h"
- #include "lm_extfuncs.h"
- #include "thread_funcs.h"
- #include "lock_globals.h"
- #include "thread_globals.h"
-
-
- int
- upgradeLock (
-
- register TRANSREC *transRec,
- register LOCKHEADER *lockHeader,
- register LOCKENTRY *lockEntry,
- LOCKMODE requestMode,
- FLAGS flags
- )
- {
-
- register LOCKMODE newMode;
-
-
- TRPRINT(TR_LOCK, TR_LEVEL_1, ("request mode:%s", GETMODE(requestMode)));
-
- /*
- * get the mode to upgrade to
- */
- newMode = LM_Convert[lockEntry->lockMode][requestMode];
- TRPRINT(TR_LOCK, TR_LEVEL_2, ("newMode:%s", GETMODE(newMode)));
-
- /*
- * remove the lock held by requestor from the list
- * and decrement the mode of the lock
- */
- listRemove( &(lockEntry->headerList.list) );
- lockHeader->modeCount[lockEntry->lockMode]--;
-
- /*
- * check to see if the request is compatible with
- * the already granted locks
- */
- if (lockCompatible(lockHeader, newMode)) {
-
- TRPRINT(TR_LOCK, TR_LEVEL_2, ("lock is compatible"));
-
- /*
- * alter the lock status
- */
- lockHeader->modeCount[newMode]++;
-
- /*
- * check for a new supremum
- */
- if (!LM_Compat_Upgrade[newMode][lockHeader->supremum]) {
-
- TRPRINT(TR_LOCK, TR_LEVEL_2, ("new supremum:%s", GETMODE(newMode)));
- lockHeader->supremum = LM_Supremum[newMode][lockHeader->supremum];
- }
-
- /*
- * put the new mode in the lock entry and put on granted list
- */
- lockEntry->lockMode = newMode;
- listPush( &(lockHeader->grantedList), &(lockEntry->headerList.list) );
- TRPRINT(TR_LOCK, TR_LEVEL_1,
- ("Thread %d, trans %ld, UPGRADing lockEntry 0x%x mode=%s flag=%d",
- Active->id, Active->message.header.params.in.tid,
- lockEntry,
- GETMODE(lockEntry->lockMode), (int)lockEntry->flags));
- TRPRINT(TR_LOCK, TR_LEVEL_1,
- ("lock (id %s) entry for trans %d",
- lockEntry->flags & LOCK_UPGRADE ?
- printLockId(((LOCKENTRY*)lockEntry->lockHeader)->lockHeader->hashList.lockid) :
- printLockId(lockEntry->lockHeader->hashList.lockid),
- lockEntry->headerList.transRec->tid) );
-
-
- /*
- * return that the lock has been granted
- */
- return(esmNOERROR);
-
- } else {
-
- register LOCKENTRY *upgradeEntry;
-
-
- TRPRINT(TR_LOCK, TR_LEVEL_2, ("lock upgrade is not grantable"));
-
- /*
- * check to see if the caller wishes to wait
- */
- if ((flags & LOCK_NOWAIT) || (flags & LOCK_INSTANT)) {
-
- /*
- * push the lock entry back onto the granted list
- * and increment the currently held mode
- */
- listPush( &(lockHeader->grantedList), &(lockEntry->headerList.list) );
- lockHeader->modeCount[lockEntry->lockMode]++;
- SM_ERROR(TYPE_USER, esmLOCKBUSY);
- return(esmFAILURE);
- }
-
- /*
- * check the deadlock
- */
- if (checkDeadlock(transRec,
- (LOCKENTRY *) FIRST_LIST_ELEMENT( &(lockHeader->grantedList) ))) {
-
- /*
- * push the lock entry back onto the granted list
- * and increment the currently held mode
- */
- listPush( &(lockHeader->grantedList), &(lockEntry->headerList.list) );
- lockHeader->modeCount[lockEntry->lockMode]++;
- return(esmFAILURE);
- }
-
- /*
- * push the lock entry back onto the granted list
- * and increment the currently held mode
- */
- listPush( &(lockHeader->grantedList), &(lockEntry->headerList.list) );
- lockHeader->modeCount[lockEntry->lockMode]++;
-
- /*
- * check to see if the request is in deadlock with any
- * other upgrades that are pending for this lock
- */
- if (checkUpgradeDeadlock(lockHeader, lockEntry->lockMode, newMode)) {
-
- return(esmFAILURE);
- }
-
- /*
- * get a new entry and put it on the upgrade list
- */
- if ((upgradeEntry =
- newLockEntry(transRec, lockHeader, UPGRADE_LIST, newMode))== NULL){
- return(esmFAILURE);
- }
-
- /*
- * initialize the information in the entry record
- *
- * CAUTION:
- * Upgrade entries contain are identical to
- * other entries except that the lockHeader
- * pointer points to the lock entry of the
- * held lock instead of the actuall lock
- * header.
- */
- upgradeEntry->lockHeader = (LOCKHEADER *) lockEntry;
-
- /*
- * mark the upgrade as pending in the master record
- */
- lockEntry->flags |= LOCK_UPGRADE_PENDING;
-
-
- TRPRINT(TR_LOCK, TR_LEVEL_1,
- ("Thread %d, trans %ld, UPGRADing lockEntry 0x%x",
- Active->id, Active->message.header.params.in.tid,
- lockEntry));
- TRPRINT(TR_LOCK, TR_LEVEL_1,
- ("upgradeEntry 0x%x, mode=%s flag=%d",
- upgradeEntry,
- GETMODE(upgradeEntry->lockMode), (int)upgradeEntry->flags));
- TRPRINT(TR_LOCK, TR_LEVEL_1,
- ("lock (id %s) entry for trans %d",
- upgradeEntry->flags & LOCK_UPGRADE ?
- printLockId(((LOCKENTRY*)upgradeEntry->lockHeader)->lockHeader->hashList.lockid) :
- printLockId(upgradeEntry->lockHeader->hashList.lockid),
- upgradeEntry->headerList.transRec->tid) );
-
- /*
- * put the thread on the wait list for this lock
- */
- return awaitLock( transRec->lock_timeout,
- upgradeEntry, THREAD_LOCKUPGRADE_WAIT);
- }
- }
-